<template>
  <div>
    <MyHeader title="购物车案例"></MyHeader>
    <MyGoods v-for="obj in list" :key="obj.id" :gObj="obj"></MyGoods>
  </div>
</template>

<script>
import MyHeader from "./MyHeader.vue";
import MyGoods from "./MyGoods.vue";
export default {
  components: {
    MyHeader,
    MyGoods,
  },
  data() {
    return {
      list: [], // 商品所有数据
    };
  },
  created() {
    // 不必在自己引入axios变量, 而是直接使用全局属性$axios
    this.$axios({
      url: "/api/cart",
    }).then((res) => {
      console.log(res);
      this.list = res.data.list;
    });
  },
};
</script>

<style>
</style>